package viper.GUI;

import java.util.ArrayList;

import viper.main.StateManager;

/**
 * @author Kevin Sin
 * 
 * Revision number: 1
 * Date created: 1/17/10
 * Date of Last Back-up on SVN: none
 * 
 * <p>JPanel for when the user is in a call.  Displays who you're talking to
 * and the relays being used.
 */
public class InCallPanel extends javax.swing.JPanel {

    /**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	/** Creates new form LoggedInJPanel */
    public InCallPanel() {
        initComponents();
    }
    

    private javax.swing.JButton jButton1; //End call button
    private javax.swing.JTextArea jTextArea; //Text area to display callee and relays

    /** This method is called from within the constructor to
     * initialize the form.
     */
    private void initComponents() {

        jButton1 = new javax.swing.JButton();
        jTextArea = new javax.swing.JTextArea();
        jTextArea.setEditable(false);

        jButton1.setText("End Call");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap(172, Short.MAX_VALUE)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jButton1)
                    .addComponent(jTextArea))
                .addGap(171, 171, 171))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(94, 94, 94)
                .addComponent(jTextArea)
                .addGap(35, 35, 35)
                .addComponent(jButton1)
                .addContainerGap(134, Short.MAX_VALUE))
        );
    }

    /**
     * @param evt
     * End call button pressed.
     */
    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {                                         
        StateManager.INSTANCE.endCall();
    }                          
    
    /**
     * Updates the display to show the relays in use.
     */
    public void update(){
    	ArrayList<Object[]> relays = StateManager.INSTANCE.getRelays();
    	String relaysString = "";
    	for(Object[] relay : relays)
    	{
    		relaysString+=relay[1] + "\n";
    	}
    	jTextArea.setText("In call w/ " + StateManager.INSTANCE.getCalleeArray()[1] + " using Relays: \n" 
    			+ relaysString);
    }

}
